import worker from '@ohos.worker';
import { GyroscopeControl, Info } from '../common/RemoteControl/GyroscopeControl'
import { FlightGearDataEncoder } from '../common/RemoteControl/Impl/FlightGearDataEncoder';

const workerPort = worker.workerPort;

let gyroscopeControl: GyroscopeControl | null = null;

workerPort.onmessage = (event) => {
  if (event.data == "start") {
    gyroscopeControl = new GyroscopeControl( 1e4);
    gyroscopeControl.setCallback((data: Info) => {
      workerPort.postMessage(data.toObject());
    });
  } else if (event.data == "stop") {
    gyroscopeControl?.close();
  }
}
